home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
prog
/
anidial.arj
/
ANIMATE.DOC
next >
Wrap
Text File
|
1994-01-23
|
8KB
|
169 lines
The Dialog Animator
By Tim Schempp
January, 1994
CompuServe Id: 71224, 455
The Dialog Animator is a relatively easy way to spice up some of your
Turbo vision Applications. This documentation will tell you everything
you need to know about using the AnimateDialog unit in your Turbo Vision
Applications.
I created the Dialog Animator to make my "About Boxes" more interesting in my
applications. The Dialog Animator will allow you to put moving views in your
Dialog Boxes. The Views still operate the same way they did before (except
you have to chase them with the mouse). The animation can be toggled by
pressing a Hot Key, clicking on a "Special View" or always left on. If you
like this unit, you can use it in any of your applications. I will really get
a kick out of seeing it used in someone else's program. I would also
appreciate any suggestions you may have that will improve the unit. I've
really had some fun writing it. These programs and units are distributed
"as is" with no expressed or implied warranties. If you decide to use this
program, it is at your own risk.
This zipped file should have included the following:
1) ANIMATE.DOC This Documentation
2) ANIMATED.PAS The Dialog Animation Unit
3) ANITEST.PAS A sample program which shows all of the animators
features.
4) SIMPLE.PAS A simple sample program which shows what's involved
with animating a Dialog Box.
Before we discuss the animator, it would be good for you to play with the
two sample programs and get a feel for what the Animator does. ANITEST.PAS
is a pretty long program, but that's how most Turbo Vision Applications are.
Although the Dialog Animator will require you to add a few lines of code to
get things working, I think you will find it easy enough once you get started.
In order to Animate a Dialog box, you must use the following. Declare the
Dialog Box as a PAnimateDialog object and add a pointer to the Dialog Box to
your application object. You would then override the applications
Idle procedure like this:
type TMyApp=object(TApplication)
MyDialog:PAnimateDialog;
procedure Idle; virtual;
procedire DoMyDialog;
end; {object}
procedure TMyApp.Init;
begin
inherited Idle;
if MyDialog<>nil then MyDialog^.Update;
end;
The pointer MyDialog is initiated to nil when your program starts
automatically. It is important that whenever the Dialog Box is not active,
the pointer MyDialog is equal to nil. Otherwise the computer will attempt to
Update a non existatant Dialog Box. This will cause your computer to freeze
(a bad thing). So whenever your Dialog Box is not active, be sure the Dialog
pointer is equal to nil.
Your next step is to create you Dialog Box. You would do that like this"
procedure TMyApp.DoMyDialog;
var R,Bounds:TRect;
AView:PView;
AniItem:PAniItem; {An animation entry object.}
begin
R.Assign(20,2,60,20);
MyDialog:=New(PAnimateDialog,Init(R,'Look an Animate Dialog Box!'));
with MyDialog^ do
begin
GetExtent(Bounds); {<-Create a Boundry for the Animation}
Inc(Bounds.B.X,-1); Inc(Bounds.B.Y,-1);
Inc(Bounds.A.X,1); Inc(Bounds.A.Y,1);
{Make A View}
R.Assign(15,13,25,15);
AView:=New(PButton,Init(R,'~O~k',cmOk,bfDefault));
Insert(AView);
{Add it to the Animation List}
AniItem:=New(PAniItem,Init(AView,Bounds,AniBounceAround,11,3,1));
AniList^.Insert(AniItem);
end; {with}
DeskTop^.ExecView(MyDialog);
Dispose(MyDialog,Done);
{*** !!! ***}
MyDialog:=nil; {Tell the App the Dialog Box is Gone}
end;
That's how you create an animate Dialog Box. Each AniItem has several fields:
P, the view that is going to be animated.
Bounds, the boundry the animation is going to take place in, usually
within the Dialog Boxes frame.
Original, the original bounds of the view before the animation took place.
Param, the type of animation to take place there are three types.
1) AniNone means that the view will move around the screen till
it encounters a boundry and then return to it's starting
place.
2) AniBounceBack means the view will bounce back off the
boundry when it encounters it.
3) AniBounceAround cause the view to bounce around within
the boundry.
DelayTime, is the number of HUNDREDTHS of a second between animation
updates. The program uses the computers internal clock to
decide when a view needs to be redrawn.
LastUpDated, denotes the last time (in hundredths of a second) the dialog box
was updated.
Xstep,Ystep denote how far in there respected directions to advance the view
in each direction.
Notice in the Dialog Box above how the variable MyDialog is very
carefully set to nil when the dialog box is destroyed. This is
important, to avoid system lock ups from accessing pointers which have been
disposed of.
The TAnimateDialog object has several fields as well, three of which you may
access directly.
UpDateOn is a Boolean variable which tells if the Dialog Box should Update
itself or not. This variable defaults to True, but can be set to
False to allow a hot key to start the View.
SpecialKey holds a keycode for toggling the variable UpDateOn. It defaults to
kbNoKey but may be set to say kbF1 or kbAltA to trigger the
animation.
Similarly, you may set the pointer SpecialView to point to a view within you
dialog box. when the user double clicks on the view, it will
trigger it. SpecialView defaults to nil. (Static Text objects
work best for triggering Dialog Box animation.) This is all
demonstrated in the WinDialog procedure in program AniTest.
It can be fun to add animation to otherwise serious programs. Consider a
Data entry screen with some static text on the top. One day the user is
clicking around the screen and accidentally clicks on the static text object.
Boom, all of the input lines start floating around the screen, or the Dialog
Box itself starts floating around the screen, or the windows behind the dialog
box start floating around the screen. When the user clicks on the text again,
everything returns to normal. It's a good idea not to animate a Dialog Boxes
trigger or the user may have trouble catching it to turn things back off.
You may also find use for the AnimateDialog Box's RestoreViews procedure which
puts all the views back in their original positions. Be sure and call this
BEFORE you dispose of the dialog box, or again you might experience a system
lock up. It is useful to call this procedure if you have animated some views
outside of the Dialog Box. In program AniTest, a ForEach statement is used to
grab all of the objects (in this case windows) in the desktop and insert them
into the AniList. When the user exits the Dialog Box, the Views are restored
to their original position using a ResotreView command, and then the Dialog
Box is Disposed of. It's not nice to make a permanent mess out of the users
DeskTop.
To really get a feel for animating Dialog Boxes, try playing with SIMPLE.PAS
and adding some views to it. How many views you animate in an application is
up to you. I mainly use this program for my "About Boxes," and sometimes I
hide a few animate Dialog Boxes with hot keys in other places of my
application. If your buttons float too fast, no one can catch them, and
that's really no fun. I hope this unit can add a little something new to your
Turbo Vision applications. Please contact me with any questions or comments
that you have.